package jm.algorithm.sort;


/**
 * @Description 选择排序
 * @date 2022/5/1 16:05
 */
public class SelectionSort<E extends Comparable<E>> extends Sort<E> {
    @Override
    protected void sort() {
        for (int end = arr.length - 1; end > 0; end--) {
            int maxIndex = 0;
            for (int start = 1; start <= end; start++) {
                if (cmp(maxIndex,start) <= 0){ // 如果有索引，大于最大值的索引，重新赋值
                    maxIndex = start;
                }
            }
            swap(maxIndex,end);
        }
    }
}
